﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using Pixysoft.Framework.Configurations;

namespace Pixysoft.Framework.Logs.Core
{
    class RecordPropertyCollection : IRecordPropertyCollection
    {
        IXmlPropertyCollection collection = null;

        public RecordPropertyCollection(IXmlPropertyCollection collection)
        {
            this.collection = collection;
        }

        public string this[string propertyname]
        {
            get
            {
                return collection[propertyname];
            }
        }

        public IRecordProperty Add(string key, string value)
        {
            IXmlProperty rproperty = collection.Add(key, value);

            return new RecordProperty(rproperty);
        }

        public void Add(IRecordProperty property)
        {
            collection.Add(property.Key, property.Value);
        }

        public IRecordProperty Add(IXmlProperty node)
        {
            IRecordProperty property = new RecordProperty(node);

            Add(property);

            return property;
        }

        public int Count
        {
            get { return collection.Count; }
        }

        public void Clear()
        {
            collection.Clear();
        }

        public bool Contains(IRecordProperty item)
        {
            return collection.Contains(item.Key);
        }

        public IRecordProperty this[int index]
        {
            get
            {
                IXmlProperty property = collection[index];

                if (property == null)
                    return null;

                return new RecordProperty(property);
            }
        }

        public bool Contains(string key)
        {
            return collection.Contains(key);
        }


        #region IEnumerable<IRecordProperty> 成员

        public IEnumerator<IRecordProperty> GetEnumerator()
        {
            return this;
        }

        #endregion

        #region IEnumerable 成员

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this;
        }

        #endregion

        #region IEnumerator<IRecordProperty> 成员

        public IRecordProperty Current
        {
            get { return new RecordProperty(collection.Current); }
        }

        #endregion

        #region IDisposable 成员

        public void Dispose()
        {
            collection.Dispose();
        }

        #endregion

        #region IEnumerator 成员

        object System.Collections.IEnumerator.Current
        {
            get
            {
                return new RecordProperty(collection.Current);
            }
        }

        public bool MoveNext()
        {
            return collection.MoveNext();
        }

        public void Reset()
        {
            collection.Reset();
        }

        #endregion

    }
}
